home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 117 / MacAddict 117.dmg / Software / Utilities / CopyRoms 0.2.0 (freeware).dmg / CopyRoms 0.2.0(freeware) / CopyRoms 0.2.0 / source / CopyRoms.c < prev    next >
Encoding:
C/C++ Source or Header  |  2005-04-12  |  7.2 KB  |  308 lines

  1. /*
  2.     CopyRoms.c
  3.  
  4.     Copyright (C) 2005 Paul Pratt
  5.  
  6.     You can redistribute this file and/or modify it under the terms
  7.     of version 2 of the GNU General Public License as published by
  8.     the Free Software Foundation.  You should have received a copy
  9.     of the license along with this file; see the file COPYING.
  10.  
  11.     This file is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     license for more details.
  15. */
  16.  
  17. /*
  18.     Much of the information about ROM checksums was found at:
  19.         "http://mes.emuunlim.com/tips/rom_checksums.htm"
  20.         "http://homepage3.nifty.com/toshi3/list.html"
  21.         "http://www.yama-arashi.com/com-mac/"
  22.         "http://www.geocities.com/va_macs4me/"
  23.         "http://dragonstar-realm.net/MacFaq/Roms.html"
  24. */
  25.  
  26. #include <types.h>
  27. #include <limits.h>
  28. #include <stddef.h>
  29. #include <SegLoad.h>
  30. #include <Script.h>
  31. #include <Files.h>
  32. #include <Devices.h>
  33. #include <Windows.h>
  34. #include <TextEdit.h>
  35. #include <Dialogs.h>
  36.  
  37. #define ROMBase 0x02AE
  38.  
  39. #define MyCreator 'MnvM'
  40. #define MyFileType 'ROM!'
  41.  
  42. QDGlobals qd;
  43.  
  44. /*
  45.     Don't have 'main', and instead have a bit of assembly
  46.     language call 'MyStart', to avoid the glue code of
  47.     a development environment that doesn't really support
  48.     Macintosh 128K
  49. */
  50.  
  51. void MyStart(void);
  52.  
  53. void MyStart(void)
  54. {
  55.     OSErr err;
  56.     unsigned long Length;
  57.     StringPtr MyFileName;
  58.     short VRefNum;
  59.     Ptr StartAddr;
  60.     unsigned long CheckSum;
  61.  
  62.     ParamBlockRec b;
  63.  
  64.     InitGraf((Ptr)&qd.thePort);
  65.     InitFonts();
  66.     InitWindows();
  67.     InitMenus();
  68.     TEInit();
  69.     InitDialogs(NULL);
  70.  
  71.     StartAddr = *(Ptr *)ROMBase;
  72.     CheckSum = *(unsigned long *)StartAddr;
  73.  
  74.     /*
  75.         Guess what ROM this is from its checksum.
  76.     */
  77.  
  78.     if ((CheckSum == 0x28BA61CE)
  79.         || (CheckSum == 0x28BA4E50))
  80.     {
  81.         Length = (64 * 1024UL);
  82.         MyFileName = ((StringPtr)"\pMac128K.ROM");
  83.     } else
  84.     if ((CheckSum == 0x4D1EEEE1)
  85.         || (CheckSum == 0x4D1EEAE1)
  86.         || (CheckSum == 0x4D1F8172))
  87.     {
  88.         Length = (128 * 1024UL);
  89.         MyFileName = ((StringPtr)"\pvMac.ROM");
  90.     } else
  91.     if (CheckSum == 0xB2E362A8)
  92.     {
  93.         Length = (256 * 1024UL);
  94.         MyFileName = ((StringPtr)"\pMacSE.ROM");
  95.     } else
  96.     if ((CheckSum == 0x9779D2C4)
  97.         || (CheckSum == 0x97851DB6))
  98.     {
  99.         Length = (256 * 1024UL);
  100.         MyFileName = ((StringPtr)"\pMacII.ROM");
  101.     } else
  102.     if (CheckSum == 0x97221136)
  103.     {
  104.         Length = (256 * 1024UL);
  105.         MyFileName = ((StringPtr)"\pMacIIx.ROM");
  106.     } else
  107.     if (CheckSum == 0xB306E171)
  108.     {
  109.         Length = (256 * 1024UL);
  110.         MyFileName = ((StringPtr)"\pSEHDFD.ROM");
  111.     } else
  112.     if (CheckSum == 0x96645F9C) {
  113.         Length = (256 * 1024UL);
  114.         MyFileName = ((StringPtr)"\pPB100.ROM");
  115.     } else
  116.     if (CheckSum == 0x368CADFE) {
  117.         Length = (512 * 1024UL);
  118.         MyFileName = ((StringPtr)"\pMacIIci.ROM");
  119.     } else
  120.     if ((CheckSum == 0x4147DD77)
  121.         || (CheckSum == 0x35C28C8F))
  122.     {
  123.         Length = (512 * 1024UL);
  124.         MyFileName = ((StringPtr)"\pMacIIfx.ROM");
  125.     } else
  126.     if (CheckSum == 0x36B7FB6C) {
  127.         Length = (512 * 1024UL);
  128.         MyFileName = ((StringPtr)"\pMacIIsi.ROM");
  129.     } else
  130.     if (CheckSum == 0xA49F9914) {
  131.         Length = (512 * 1024UL);
  132.         MyFileName = ((StringPtr)"\pClassic.ROM");
  133.     } else
  134.     if (CheckSum == 0x350EACF0) {
  135.         Length = (512 * 1024UL);
  136.         MyFileName = ((StringPtr)"\pMacLC.ROM");
  137.     } else
  138.     if (CheckSum == 0x3193670E) {
  139.         Length = (512 * 1024UL);
  140.         MyFileName = ((StringPtr)"\pClassicII.ROM");
  141.     } else
  142.     if (CheckSum == 0x420DBFF3) {
  143.         Length = (1024 * 1024UL);
  144.         MyFileName = ((StringPtr)"\pQuad900.ROM");
  145.     } else
  146.     if (CheckSum == 0x35C28F5F) {
  147.         Length = (512 * 1024UL);
  148.         MyFileName = ((StringPtr)"\pMacLCII.ROM");
  149.     } else
  150.     if (CheckSum == 0x3DC27823) {
  151.         Length = (1024 * 1024UL);
  152.         MyFileName = ((StringPtr)"\pQuad950.ROM");
  153.     } else
  154.     if (CheckSum == 0x49579803) {
  155.         Length = (1024 * 1024UL);
  156.         MyFileName = ((StringPtr)"\pMacIIvx.ROM");
  157.     } else
  158.     if (CheckSum == 0xE33B2724) {
  159.         Length = (1024 * 1024UL);
  160.         MyFileName = ((StringPtr)"\pPB165.ROM");
  161.     } else
  162.     if ((CheckSum == 0xECFA989B)
  163.         || (CheckSum == 0xECFA89A8))
  164.     {
  165.         Length = (1024 * 1024UL);
  166.         MyFileName = ((StringPtr)"\pDuo230.ROM");
  167.     } else
  168.     if (CheckSum == 0xECD99DC0) {
  169.         Length = (1024 * 1024UL);
  170.         MyFileName = ((StringPtr)"\pClrClssc.ROM");
  171.     } else
  172.     if (CheckSum == 0xECBBC41C) {
  173.         Length = (1024 * 1024UL);
  174.         MyFileName = ((StringPtr)"\pMacLCIII.ROM");
  175.     } else
  176.     if (CheckSum == 0xF1A6F343) {
  177.         Length = (1024 * 1024UL);
  178.         MyFileName = ((StringPtr)"\pQuad610.ROM");
  179.     } else
  180.     if (CheckSum == 0xF1ACAD13) {
  181.         Length = (1024 * 1024UL);
  182.         MyFileName = ((StringPtr)"\pQuad650.ROM");
  183.     } else
  184.     if (CheckSum == 0x5BF10FD1) {
  185.         Length = (2 * 1024 * 1024UL);
  186.         MyFileName = ((StringPtr)"\pQuad660.ROM");
  187.     } else
  188.     if (CheckSum == 0xFF7439EE) {
  189.         Length = (1024 * 1024UL);
  190.         MyFileName = ((StringPtr)"\pMacLC475.ROM");
  191.     } else
  192.     if (CheckSum == 0x0024D346)
  193.     {
  194.         Length = (1024 * 1024UL);
  195.         MyFileName = ((StringPtr)"\pDuo270.ROM");
  196.     } else
  197.     if ((CheckSum == 0xEDE66CBD)
  198.         || (CheckSum == 0xEAF1678D))
  199.     {
  200.         Length = (1024 * 1024UL);
  201.         MyFileName = ((StringPtr)"\pMacLC550.ROM");
  202.     } else
  203.     if (CheckSum == 0x015621D7)
  204.     {
  205.         Length = (1024 * 1024UL);
  206.         MyFileName = ((StringPtr)"\pDuo280.ROM");
  207.     } else
  208.     if (CheckSum == 0xB6909089) {
  209.         Length = (1024 * 1024UL);
  210.         MyFileName = ((StringPtr)"\pPB520.ROM");
  211.     } else
  212.     if (CheckSum == 0x06684214) {
  213.         Length = (1024 * 1024UL);
  214.         MyFileName = ((StringPtr)"\pMacLC630.ROM");
  215.     } else
  216.     if (CheckSum == 0xFDA22562) {
  217.         Length = (1024 * 1024UL);
  218.         MyFileName = ((StringPtr)"\pPB150.ROM");
  219.     } else
  220.     if (CheckSum == 0x064DC91D) {
  221.         Length = (1024 * 1024UL);
  222.         MyFileName = ((StringPtr)"\pMacLC580.ROM");
  223.     } else
  224.     {
  225.  
  226. #if 0
  227. /*
  228.     this attempts to find the size of the ROM,
  229.     but is it always safe? i.e. what if ROM
  230.     doesn't repeat, reading from a random memory
  231.     mapped device could have unpleasant
  232.     results.
  233. */
  234.         unsigned int L2Length;
  235.         int i;
  236.         unsigned long *p1;
  237.         unsigned long *p2;
  238.  
  239.         L2Length = 16;
  240. Label_1:
  241.         Length = 1 << L2Length;
  242.         p1 = (unsigned long *)StartAddr;
  243.         p2 = (unsigned long *)(StartAddr + Length);
  244.         for (i = 256; --i >=0; ) {
  245.             if (*p1++ != *p2++) {
  246.                 L2Length++;
  247.                 if (L2Length < 24) {
  248.                     goto Label_1;
  249.                 } else {
  250.                     /* can't find rom size */
  251.                     L2Length = 10;
  252.                     Length = 1 << L2Length;
  253.                     goto Label_2;
  254.                 }
  255.             }
  256.         }
  257. Label_2:
  258. #else
  259.         /* so instead, just write out the checksum */
  260.         Length = 4;
  261. #endif
  262.         MyFileName = ((StringPtr)"\pUnknown.ROM");
  263.     }
  264.  
  265.     /*
  266.         use low level calls, since glue for higher level
  267.         calls provided with my development environment do not
  268.         work on Macintosh 128K
  269.     */
  270.  
  271.     b.ioParam.ioCompletion = 0;
  272.     b.ioParam.ioNamePtr = 0;
  273.     if (0 == PBGetVol(&b, false)) {
  274.  
  275.         VRefNum = b.ioParam.ioVRefNum;
  276.         b.ioParam.ioNamePtr = MyFileName;
  277.         b.ioParam.ioVersNum = 0;
  278.         err = PBCreate(&b, false);
  279.         if (err == dupFNErr) {
  280.             if (0 == PBDelete(&b, false)) {
  281.                 err = PBCreate(&b, false);
  282.             }
  283.         }
  284.         if (0 == err) {
  285.             b.ioParam.ioPermssn = fsRdWrPerm;
  286.             b.ioParam.ioMisc = 0;
  287.             if (0 == PBOpen(&b, false)) {
  288.                 b.ioParam.ioBuffer = (Ptr)(StartAddr);
  289.                 b.ioParam.ioReqCount = Length;
  290.                 b.ioParam.ioPosMode = fsFromStart;
  291.                 b.ioParam.ioPosOffset = 0;
  292.                 (void) PBWrite(&b, false);
  293.                 (void) PBClose(&b, false);
  294.  
  295.                 b.fileParam.ioNamePtr = MyFileName;
  296.                 b.fileParam.ioVRefNum = VRefNum;
  297.                 b.fileParam.ioFVersNum = 0;
  298.                 b.fileParam.ioFDirIndex = 0;
  299.                 if (0 == PBGetFInfo(&b, false)) {
  300.                     b.fileParam.ioFlFndrInfo.fdType = MyFileType;
  301.                     b.fileParam.ioFlFndrInfo.fdCreator = MyCreator;
  302.                     (void) PBSetFInfo(&b, false);
  303.                 }
  304.             }
  305.         }
  306.     }
  307. }
  308.